<?php
namespace Site\Controller;
class CategoryController extends CommonController {
    public function index() {
        $data = $this->getPageList(M('Category'),array('sid'=>$this->sid),'sort desc');
        $this->display();
    }

    public function add() {
        if(IS_POST) {
            D('Category','Mysql')->addCategory(I('post.'));
            $this->success('分类添加成功','/category');
        }
        $this->display();
    }

    public function update() {
        if(IS_POST) {
            D('Category','Mysql')->updateCategory(I('post.'));
            $this->success('分类修改成功','/category');
        }else {
            $id = I('get.id');
            verify($id,'isID','非法分类ID');

            $categoryInfo = M('Category')->find($id);
            verify($categoryInfo,'notEmpty','分类不存在');

            $this->assign('categoryInfo',$categoryInfo);
            $this->setTitle('分类管理','修改分类');
            $this->display();
        }
    }
}
?>
